import axios from 'axios';
import Cookies from 'js-cookie';
import sign from '../tool/loginSign';
//import store from '../store/index';

// 创建实例
const Instance = axios.create({
    // baseURL: ajaxUrl,
    timeout: 1000 * 60, // 30秒超时
    headers: {'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'},
    transformRequest: [function (data) {
        if (data === undefined) {
            return data
        }
        // 参数转换处理
        let ret = ''
        for (let it in data) {
            if(data[it] == null){
                data[it] = '';
            }
            ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
        }
        return ret
    }]
});

// 全局拦截器设置
Instance.interceptors.request.use(config => {
	//  ================begin ===================
//	store.commit('isLoading',{showLoading:true});


	//  ================end   ===================
    return config;
}, (error) => {
    return Promise.reject(error);
});

// response统一处理操作
Instance.interceptors.response.use(res => {
    if (res.headers && (res.headers['content-type'] === 'application/vnd.ms-excel;charset=UTF-8')) {
        downloadUrl(res.request.responseURL);
    }
    return res.data;
}, (error) => {
    // codeManger.$Message.error(error.response.data.errMsg);
    return Promise.reject(error);
});

export default Instance;
